import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import NProgress from 'nprogress'
const routes = [
    // {
    //     path: '/',
    //     redirect: '/home'
    // },
    {
        path: "/home",
        component: () =>
            import(/* webpackChunkName: "about" */ "@/view/home.vue")
    },
    {
        path: "/login",
        component: () =>
            import(/* webpackChunkName: "about" */ "@/view/login.vue")
    }
]
const router = createRouter(
    {
        routes,
        history: createWebHistory(),
    }
)
router.beforeEach((to, from, next) => {
    NProgress.start()
    let token = localStorage.getItem('token')
    // 没登陆就进入登陆页面
    if (to.path == '/login') next()
    if (token) {
        next()
    } else {
        next("/login")
        NProgress.done()
    }

})
router.beforeEach(() => {
    NProgress.done()
})
export default router